package com.yungu.swift.api.route.v2.passenger;

import com.alibaba.dubbo.config.annotation.Reference;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.model.api.ApiPageParam;
import com.yungu.swift.common.model.dto.CommonFeedbackDto;
import com.yungu.swift.common.model.param.ApiFeedbackParam;
import com.yungu.swift.common.service.CommonFeedbackService;
import com.yungu.swift.common.service.CommonSensitiveWordService;
import com.yungu.swift.constants.CommonConstant;
import com.yungu.swift.utils.MapUtils;
import com.yungu.swift.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.Map;

/**
 * @author : cuixiuyin
 * @date : 2019/11/21
 */
@RestController
@RequestMapping(value = "/api/v2/passenger/token/feedback")
@Api(value = "【乘客】【反馈】乘客反馈接口V2", tags = "V2-乘客反馈接口")
public class PasFeedbackApi {

    @Reference
    private CommonFeedbackService commonFeedbackService;
    @Reference
    private CommonSensitiveWordService commonSensitiveWordService;

    @PostMapping(value = {"/add"})
    @ApiOperation(value = "添加反馈接口")
    public ResponseData<Boolean> addFeedback(@RequestBody ApiFeedbackParam feedbackParam) {
        ResponseData<String> sensitiveWordsCheck = commonSensitiveWordService.checkContainSensitiveWords(feedbackParam.getContent(), 2);
        if (!sensitiveWordsCheck.isSuccess()) {
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "反馈信息中包含敏感词" + sensitiveWordsCheck.getData());
        }
        CommonFeedbackDto feedbackDto = new CommonFeedbackDto();
        feedbackDto.setUuid(StringUtils.buildUUID());
        feedbackDto.setAppid(feedbackParam.getAppid());
        feedbackDto.setContent(feedbackParam.getContent());
        feedbackDto.setTitle(feedbackParam.getTitle());
        feedbackDto.setIdentity(CommonConstant.PASSENGER);
        feedbackDto.setUserUuid(feedbackParam.getUserUuid());
        feedbackDto.setStatus(CommonFeedbackDto.STATUS_UNREPLY);
        feedbackDto.setCreateOn(new Date());
        feedbackDto.setCreateBy(feedbackParam.getUserUuid());
        return commonFeedbackService.add(feedbackDto);
    }

    @PostMapping(value = {"/list"})
    @ApiOperation(value = "获取反馈列表接口")
    public ResponseData<PageList<CommonFeedbackDto>> findFeedbackList(@RequestBody ApiPageParam apiPageParam) {
        Map<String, Object> map = MapUtils.build(4);
        map.put("userUuid", apiPageParam.getUserUuid());
        map.put("identity", CommonConstant.PASSENGER);
        return commonFeedbackService.queryPage(map, apiPageParam);
    }
}
